package com.ruoyi.web.controller.swimming;

import java.util.List;

import com.ruoyi.swimming.domian.SwimmingPool;
import com.ruoyi.swimming.service.ISwimmingPoolService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 泳池Controller
 * 
 * @author ruoyi
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/system/pool")
public class SwimmingPoolController extends BaseController
{
    @Autowired
    private ISwimmingPoolService swimmingPoolService;

    /**
     * 查询泳池列表
     */
    @PreAuthorize("@ss.hasPermi('system:pool:list')")
    @GetMapping("/list")
    public TableDataInfo list(SwimmingPool swimmingPool)
    {
        startPage();
        List<SwimmingPool> list = swimmingPoolService.selectSwimmingPoolList(swimmingPool);
        return getDataTable(list);
    }

    /**
     * 导出泳池列表
     */
    @PreAuthorize("@ss.hasPermi('system:pool:export')")
    @Log(title = "泳池", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SwimmingPool swimmingPool)
    {
        List<SwimmingPool> list = swimmingPoolService.selectSwimmingPoolList(swimmingPool);
        ExcelUtil<SwimmingPool> util = new ExcelUtil<SwimmingPool>(SwimmingPool.class);
        return util.exportExcel(list, "泳池数据");
    }

    /**
     * 获取泳池详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pool:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(swimmingPoolService.selectSwimmingPoolById(id));
    }

    /**
     * 新增泳池
     */
    @PreAuthorize("@ss.hasPermi('system:pool:add')")
    @Log(title = "泳池", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SwimmingPool swimmingPool)
    {
        return toAjax(swimmingPoolService.insertSwimmingPool(swimmingPool));
    }

    /**
     * 修改泳池
     */
    @PreAuthorize("@ss.hasPermi('system:pool:edit')")
    @Log(title = "泳池", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SwimmingPool swimmingPool)
    {
        return toAjax(swimmingPoolService.updateSwimmingPool(swimmingPool));
    }

    /**
     * 删除泳池
     */
    @PreAuthorize("@ss.hasPermi('system:pool:remove')")
    @Log(title = "泳池", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(swimmingPoolService.deleteSwimmingPoolByIds(ids));
    }
}
